﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Baopx_API;

namespace A.Controller
{
    public class NewsCategoryController
    {
        public static void Insert(NewsCategory newsCategory)
        {
            A.M.d.NewsCategories.InsertOnSubmit(newsCategory);
            A.M.d.SubmitChanges();
        }

        public static void Update()
        {
            A.M.d.SubmitChanges();
        }

        public static void Delete(NewsCategory newsCategory)
        {
            A.M.d.NewsCategories.DeleteOnSubmit(newsCategory);
            A.M.d.SubmitChanges();
        }

        public static NewsCategory GetElementById(int id)
        {
            return A.M.d.NewsCategories.SingleOrDefault(i => i.Id == id);
        }

        public static List<NewsCategory> GetAll()
        {
            return A.M.d.NewsCategories.ToList();
        }

        public static List<NewsCategory> GetAllCategoryParent()
        {
            return A.M.d.NewsCategories.Where(i => i.ParentId == null).ToList();
        }

        public static List<NewsCategory> GetAllCategorySub()
        {
            return A.M.d.NewsCategories.Where(i => i.ParentId != null).ToList();
        }
    }
}
